﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Model;
using AspNetCs.Bll;
using System.Data;
using System.Collections;
using AspNetCs.Enumerations;
using AspNetCs.Enumerations.memorial_enum;
using AspNetCs.Enumerations.User_Enum;
using AspNetCs.Common;
using AspNetCs.Enumerations.Channel_Enum;
using AspNetCs.Enumerations.TrueOrFalseEnum;

public partial class Users_FindFamilyList : BasePage
{
    private FindFamilyBLL bll = new FindFamilyBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckUserExit("Login.Aspx?ReUrl=" + configInfo.InstallDir + "Users/FindFamilyList.aspx", "请您登录", true);
        if (!IsPostBack)
        {
            getMyAddFindFamily();
        }

    }

    private void getMyAddFindFamily()
    {
        Users_Model userModel = Base_GetUserInfo;
        string propertyItems = " id,ItemName,PreName,PostfixName,Sex,RegisterTime,IsCheck,OtherName,title ";
        DataTable dataTable = bll.SearchUserCreateFamilyInfo(propertyItems, userModel.UserId, 2);
        rptFindFamilys.DataSource = dataTable;
        rptFindFamilys.DataBind();
    }

    private bool deleteFindFamily(int id)
    {
        int count = 0;
        count = bll.HiddenFamilyInfo(id);
        return count > 0 ? true : false;
    }

    protected void rptFindFamilys_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        bool bo = false;
        //Response.Write("<script>alert('"+btnDelete.CommandArgument+"');</script>");
        if (e.CommandName == "delete")
        {
            LinkButton btnDelete = e.Item.FindControl("btnDelete") as LinkButton;
            if (btnDelete != null)
            {
                string id = btnDelete.CommandArgument;
                try
                {
                    bo = deleteFindFamily(Convert.ToInt32(id));
                }
                catch
                {
                    bo = false;
                }
            }
        }
        else if (e.CommandName == "manage")
        {
            LinkButton btnManage = e.Item.FindControl("btnManage") as LinkButton;
            if (btnManage != null)
            {
                string id = btnManage.CommandArgument;
                try
                {
                    Response.Redirect("UpdateFindFamily_" + Convert.ToInt32(id) + ".aspx");
                }
                catch
                {
                }
            }
        }
        else if (e.CommandName == "createhtml")
        {
            try
            {
                List<FindFamilyModel> list = FindFamily_Bll.CreatNew.GetList(" id=" + e.CommandArgument.ToString());
                if (list[0].IsCheck == (int)IsTrueEnum.NO)
                {
                    Response.Write("<script>alert('当前信息未通过审核，无法生成');history.back();</script>");
                    Response.End();
                }
                else
                {

                    string NumUrl = list[0].Id + ".html";

                    string CreateHtmlUrl = configInfo.InstallDir + "Html/" + Channel_Type.FindFamily.ToString() + "/" + NumUrl;
                    TempleBll.CreateNew.TempleCreate(Server.MapPath(CreateHtmlUrl), NumUrl, Channel_Type.FindFamily, true);

                    Response.Write("<script>alert('生成成功');location.href='FindFamilyList.aspx';</script>");
                    Response.End();
                }
            }
            catch
            {
                Response.Write("<script>alert('出错了!');history.back();</script>");
                Response.End();
            }

            Response.End();
        }
        getMyAddFindFamily();
    }



    protected void rptFindFamilys_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Label lblCheck = e.Item.FindControl("lblCheck") as Label;
        HiddenField hldCheck = e.Item.FindControl("hldCheck") as HiddenField;

        if (lblCheck != null && hldCheck != null)
        {
            if (StringHelper.isNumber_int(hldCheck.Value) == 0)
            {
                lblCheck.Text = "等待审核";
            }
            else if (StringHelper.isNumber_int(hldCheck.Value) == 1)
            {
                lblCheck.Text = "审核通过";
            }
        }
    }
}
